package cn.lrwjz.androidguide.ui;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import cn.lrwjz.androidguide.R;

/**
 * FAB示例Activity
 * 展示Material Design浮动操作按钮的使用方法
 */
public class FabActivity extends AppCompatActivity {
    private boolean isExtended = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fab);

        // 设置工具栏
        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("FAB 示例");
        }

        // 基础FAB点击事件
        FloatingActionButton basicFab = findViewById(R.id.basicFab);
        basicFab.setOnClickListener(v -> 
            Toast.makeText(this, "点击了基础FAB", Toast.LENGTH_SHORT).show());

        // 迷你FAB点击事件
        FloatingActionButton miniFab = findViewById(R.id.miniFab);
        miniFab.setOnClickListener(v -> 
            Toast.makeText(this, "点击了迷你FAB", Toast.LENGTH_SHORT).show());

        // 扩展FAB点击事件
        ExtendedFloatingActionButton extendedFab = findViewById(R.id.extendedFab);
        extendedFab.setOnClickListener(v -> {
            if (isExtended) {
                extendedFab.shrink();
                isExtended = false;
            } else {
                extendedFab.extend();
                isExtended = true;
            }
            Toast.makeText(this, 
                isExtended ? "FAB已展开" : "FAB已收缩", 
                Toast.LENGTH_SHORT).show();
        });

        // 动作FAB点击事件
        FloatingActionButton actionFab = findViewById(R.id.actionFab);
        actionFab.setOnClickListener(v -> 
            Toast.makeText(this, "点击了动作FAB", Toast.LENGTH_SHORT).show());
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
} 